package cn.fzm.ssm.service.impl;

import cn.fzm.ssm.dao.IRoleDao;
import cn.fzm.ssm.domain.Role;
import cn.fzm.ssm.service.IRoleService;
import cn.fzm.ssm.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Dremeue
 * @create 2019-10-13 1:22
 **/
@Service
@Transactional
public class RoleService implements IRoleService {

    @Autowired
    private IRoleDao rolesDao;

    @Override
    public List<Role> findAll() {
        return rolesDao.findAll();
    }

    @Override
    public void save(Role role) {
        role.setId(UUIDUtils.getUUID());
        rolesDao.save(role);
    }

    @Override
    public List<Role> findOtherRole(String id) {
        return rolesDao.findOtherRole(id);
    }

    @Override
    public Role findById(String id) {
        return rolesDao.findById(id);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] ids) {
        for (String permissionId : ids) {
            rolesDao.addPermissionToRole(permissionId, roleId);
        }
    }
}
